/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package org.mobiubiq.directory.client.frame.service;

import javax.microedition.io.ConnectionNotFoundException;
import org.kalmeo.kuix.core.Kuix;
import org.kalmeo.kuix.core.KuixMIDlet;
import org.mobiubiq.directory.client.data.Service;

/**
 *
 * @author Marnix Renne
 */
public class PlatformRequestServiceFrame implements ServiceHandlerFrame {
    public static final String PROTOCOL = "http";
    private Service service;
    
    public PlatformRequestServiceFrame(Service service) {
        super();
        this.service = service;
    }
    
    public boolean onMessage(Object identifier, Object[] arguments) {
        return true;
    }

    public void onAdded() {
        try {
            KuixMIDlet midlet = KuixMIDlet.getDefault();
            midlet.platformRequest(getService().getUrl());
            midlet.notifyDestroyed();
        } catch (ConnectionNotFoundException ex) {
            Kuix.alert(ex);
        }
    }

    public void onRemoved() {
    }

    public String getProtocol() {
        return PROTOCOL;
    }
    
    public Service getService() {
        return service;
    }
    
    public static boolean accepts(String uri) {
        if(uri.startsWith("sms:")) {
            return true;
        }
        if(uri.startsWith("http:")) {
            return true;
        }
        if(uri.startsWith("https:")) {
            return true;
        }
        return false;
    }
}
